package com.xian.ai.code.core.saver;


import com.xian.ai.code.ai.model.HtmlCodeResult;
import com.xian.ai.code.ai.model.MultiFileCodeResult;
import com.xian.ai.code.exception.BusinessException;
import com.xian.ai.code.exception.ErrorCode;
import com.xian.ai.code.model.enums.CodeGenTypeEnum;

import java.io.File;

/**
 * @ClassName CodeFileSaveExecutor
 * @Description 文件保存执行器
 * @Author Zhangxn
 * @Version 1.0
 */
public class CodeFileSaveExecutor {
    private static final HtmlCodeFileSaveTemplate htmlCodeFileSaveTemplate=new HtmlCodeFileSaveTemplate();
    private static final MultiFilesCodeSaveTemplate multiFilesCodeSaveTemplate=new MultiFilesCodeSaveTemplate();
    public static File executorFileEcecutor(Object result, CodeGenTypeEnum genTypeEnum,Long appId){
        return switch (genTypeEnum){
            case HTML->htmlCodeFileSaveTemplate.saveCode((HtmlCodeResult)result,appId);
            case MULTI_FILE->multiFilesCodeSaveTemplate.saveCode((MultiFileCodeResult)result,appId);
            default-> throw new BusinessException(ErrorCode.PARAMS_ERROR,"不支持这种类型的文件保存");
        };
    }
}
